<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;

class FileController extends Controller
{
    public function store(Request $request)
    {
        if (!$request->hasFile('file')) {
            return ['code' => 1, 'msg' => '上传失败', 'data' => []];
        }
        $file = $request->file('file');
        $path = 'uploads/maintain/' . date('Ymd');
        $filename = time() . '_' . $file->getClientOriginalName();
        $fileUrl = $file->storeAs($path, $filename, 'public');
        // 存储文件，并生成公开链接
        $url = Storage::url($fileUrl);
        return ['code' => 0, 'msg' => '上传成功', 'data' => ['src'=>$url]];
    }
}
